import type {baseResponse, listResponse, paramsType} from "@/api/index";
import {useAxios} from "@/api/index";

export interface orderType {
    "id": number
    "createdAt": string
    "userID": number
    "no": string
    "price": number // 金额 单位分
    "scope": number // 购买的积分
    "payStatus": number // 支付状态  1 // 未支付  2 // 已支付  3 // 支付超时
    "paySource": number // 支付的来源  1 支付宝 2 微信
    "payUrl": string
    "payedTime": null,
    "deletedAt": null,
    "userNickname": string
    "userAvatar": string
}

export interface orderListParamsType extends paramsType {
    payStatus?: number
    no?: string
    isDeleted?: boolean // 是否查询被删除的数据
}


export interface orderCreateRequest {
    payType: number // 1 支付宝 2 wx
    price: number // 100 500 1000
}


export function orderListApi(params?: orderListParamsType): Promise<baseResponse<listResponse<orderType>>> {
    return useAxios.get("/api/order", {params})
}
export function orderStatusApi(no: string): Promise<baseResponse<{ payStatus: number }>> {
    return useAxios.get("/api/order/status", {params: {no}})
}
export interface orderCreateResponse {
    no: string
    payUrl: string
    price: number
}

export function orderCreateApi(data: orderCreateRequest):Promise<baseResponse<orderCreateResponse>>{
    return  useAxios.post("/api/order", data)
}

